/**
 * 处理报表类页面-标线样式的方法
 * */
export default {
	data() {
		return {
			onlyKeyName: 'id',
			checkDataItem: {},
			bgColor: '#e6f7ff',
			borderColor: '#e8eaec'
		};
	},
	methods: {
		// 对已选择的数据进行标记
		markData(data = []) {
			let arr = [];
			arr = data ? data.map(x => {
				x.isCheck = false;
				if (Object.keys(this.checkDataItem).length && x[this.onlyKeyName] === this.checkDataItem.id) {
					this.$set(x, 'isCheck', true);
				}
				return x;
			}) : [];
			return arr;
		},
		headerCellStyle({ row, column }) {
			if (column.field && this.checkDataItem.keyName && column.field === this.checkDataItem.keyName) {
				return {
					boxShadow: `inset 0 0 0px 0.5px ${this.borderColor}`,
					background: this.bgColor
				};
			}
		},
		onCellClick({ row, column }) {
			if (this.checkDataItem && this.checkDataItem.id === row[this.onlyKeyName] && this.checkDataItem.keyName === column.field) {
				this.checkDataItem = {};
			} else {
				this.checkDataItem = {
					id: row[this.onlyKeyName],
					keyName: column.field
				};
			}
			this.tableData.forEach(x => {
				this.$set(x, 'isCheck', false);
				if (x[this.onlyKeyName] === this.checkDataItem.id) {
					this.$set(x, 'isCheck', true);
				}
			});
		},
		cellStyle(e) {
			let styleCfg = {};
			if (Object.keys(this.checkDataItem).length && (e.column.field === this.checkDataItem.keyName || e.row.isCheck)) {
				styleCfg = {
					boxShadow: `inset 0 0 0px 0.5px ${this.borderColor}`,
					background: this.bgColor
				};
			} else {
				if (e.row.ifOpen) {
					styleCfg = {
						boxShadow: `inset 0 0 0px 0.5px ${this.borderColor}`,
						background: this.bgColor
					};
				}
			}
			return styleCfg;
		}
	}
};
